*****************************
 * Corruption and Covid
 * June 1, 2020
 *****************************
 
 **********************
 * S1 Generate Event
 **********************
 
  gl dirraiz "/Users/adansilverio/Dropbox/Paper 32 IMCO Adan"
*  gl dirraiz "C:\Users\prude\OneDrive - Instituto Tecnologico y de Estudios Superiores de Monterrey\Tec\Research\Corruption\Paper 32 IMCO Adan"
*  gl dirraiz "C:\Users\prude\Dropbox\Paper 32 IMCO Adan"

 * Event
  
  clear all
  use "${dirraiz}/Data/BASE_PANEL.dta"
 
  gen even=.
  
  replace even=-9 if month_inicio==6 & year_inicio==2019 
  replace even=-8 if month_inicio==7 & year_inicio==2019 
  replace even=-7 if month_inicio==8 & year_inicio==2019 
  replace even=-6 if month_inicio==9 & year_inicio==2019 
  replace even=-5 if month_inicio==10 & year_inicio==2019 
  replace even=-4 if month_inicio==11 & year_inicio==2019
  replace even=-3 if month_inicio==12 & year_inicio==2019
 
  replace even=-2 if month_inicio==1 & year_inicio==2020 
  replace even=-1 if month_inicio==2 & year_inicio==2020 
  replace even=0 if month_inicio==3 & year_inicio==2020   
  replace even=1 if month_inicio==4 & year_inicio==2020  
  replace even=2 if month_inicio==5 & year_inicio==2020 
  replace even=3 if month_inicio==6 & year_inicio==2020 
  replace even=4 if month_inicio==7 & year_inicio==2020  
  replace even=5 if month_inicio==8 & year_inicio==2020 
  replace even=6 if month_inicio==9 & year_inicio==2020  
  replace even=7 if month_inicio==10 & year_inicio==2020
  replace even=8 if month_inicio==11 & year_inicio==2020  
  replace even=9 if month_inicio==12 & year_inicio==2020 
  
  recode even (.=-1) /* Controles */
  tab even
  
  tab year_inicio if even==-1
  
  save "${dirraiz}/Data/BASE_PANEL.dta", replace
  
 
   
 ***********************
 * S2 Table & Figures
 ***********************
  
 
 *************************************
 * Table 1 Descriptive Statistics
 *************************************
 
 gen ave_value_cont= (monto/count_contracts)/1000000
 
 sum ave_value_cont count_contracts  pct_cont_disc pct_disc
 sum ave_value_cont count_contracts  pct_cont_disc pct_disc if inst_salud==1
 sum ave_value_cont count_contracts  pct_cont_disc pct_disc if inst_salud==0
 
 *************************
 * Tabla 2: Dif in Dif
 *************************
 
 
 gen COVID=0
 replace COVID=1 if even>=0 & even<=9
 tab even COVID 
 
 
 qui reghdfe  pct_cont_disc COVID i.month_inicio i.year_inicio, absorb(i.inst_factor) cluster(inst_factor)
 est store A
 qui reghdfe  pct_cont_disc COVID i.month_inicio i.year_inicio if inst_salud==1, absorb(i.inst_factor) cluster(inst_factor)
 est store B
 qui reghdfe  pct_cont_disc COVID i.month_inicio i.year_inicio if inst_salud==0, absorb(i.inst_factor) cluster(inst_factor)
 est store C

  esttab A B C   ///
  using  "${dirraiz}/Output/Tabla2a.tex", replace ///
  b(3) se(3) se label star(* 0.1 ** 0.05 *** 0.01) ///
  title(OLS Estimates:   \label{lpmpsycho}) ///
  nomtitles r2(2) obslast 
 
 sum pct_cont_disc          if COVID==0
 sum pct_cont_disc          if COVID==0 &  inst_salud==1 
 sum pct_cont_disc          if COVID==0 &  inst_salud==0 
 
 
 qui reghdfe  pct_disc COVID i.month_inicio i.year_inicio, absorb(i.inst_factor) cluster(inst_factor)
 est store A
 qui reghdfe  pct_disc COVID i.month_inicio i.year_inicio if inst_salud==1, absorb(i.inst_factor) cluster(inst_factor)
 est store B
 qui reghdfe  pct_disc COVID i.month_inicio i.year_inicio if inst_salud==0, absorb(i.inst_factor) cluster(inst_factor)
 est store C
 
  esttab A B C  ///
  using  "${dirraiz}/Output/Tabla2b.tex", replace ///
  b(3) se(3) se label star(* 0.1 ** 0.05 *** 0.01) ///
  title(OLS Estimates:   \label{lpmpsycho}) ///
  nomtitles r2(2) obslast 
 
 sum pct_cont_disc pct_disc if COVID==0
 sum               pct_disc if COVID==0 &  inst_salud==1
 sum               pct_disc if COVID==0 &  inst_salud==0
 
 bysort COVID: sum pct_disc 
 bysort COVID: sum pct_disc if inst_salud == 1
 bysort COVID: sum pct_disc if inst_salud == 0
 * vs
 sum pct_disc 
 sum pct_disc if inst_salud == 1
 sum pct_disc if inst_salud == 0
 
 
 
 save "${dirraiz}/Data/BASE_PANEL.dta", replace
 
 
 
 ************************************************
 * Table  Robustness - DD with all institutions
 ************************************************
 
  clear all
  use "${dirraiz}/Data/BASE_PANEL_nodrop.dta"
 
  gen even=.
  
  replace even=-9 if month_inicio==6 & year_inicio==2019 
  replace even=-8 if month_inicio==7 & year_inicio==2019 
  replace even=-7 if month_inicio==8 & year_inicio==2019 
  replace even=-6 if month_inicio==9 & year_inicio==2019 
  replace even=-5 if month_inicio==10 & year_inicio==2019 
  replace even=-4 if month_inicio==11 & year_inicio==2019
  replace even=-3 if month_inicio==12 & year_inicio==2019
 
  replace even=-2 if month_inicio==1 & year_inicio==2020 
  replace even=-1 if month_inicio==2 & year_inicio==2020 
  replace even=0 if month_inicio==3 & year_inicio==2020   
  replace even=1 if month_inicio==4 & year_inicio==2020  
  replace even=2 if month_inicio==5 & year_inicio==2020 
  replace even=3 if month_inicio==6 & year_inicio==2020 
  replace even=4 if month_inicio==7 & year_inicio==2020  
  replace even=5 if month_inicio==8 & year_inicio==2020 
  replace even=6 if month_inicio==9 & year_inicio==2020  
  replace even=7 if month_inicio==10 & year_inicio==2020
  replace even=8 if month_inicio==11 & year_inicio==2020  
  replace even=9 if month_inicio==12 & year_inicio==2020 
  
  recode even (.=-1) /* Controles */
  tab even
  
  tab year_inicio if even==-1
  
 gen COVID=0
 replace COVID=1 if even>=0 & even<=9
 tab even COVID 
 
 
 qui reghdfe  pct_cont_disc COVID i.month_inicio i.year_inicio, absorb(i.inst_factor) cluster(inst_factor)
 est store A
 qui reghdfe  pct_cont_disc COVID i.month_inicio i.year_inicio if inst_salud==1, absorb(i.inst_factor) cluster(inst_factor)
 est store B
 qui reghdfe  pct_cont_disc COVID i.month_inicio i.year_inicio if inst_salud==0, absorb(i.inst_factor) cluster(inst_factor)
 est store C

  esttab A B C   ///
  using  "${dirraiz}/Output/Tabla2a_robust_nodrop.tex", replace ///
  b(3) se(3) se label star(* 0.1 ** 0.05 *** 0.01) ///
  title(OLS Estimates:   \label{lpmpsycho}) ///
  nomtitles r2(2) obslast 
 
 sum pct_cont_disc          if COVID==0
 sum pct_cont_disc          if COVID==0 &  inst_salud==1 
 sum pct_cont_disc          if COVID==0 &  inst_salud==0 
 
 
 qui reghdfe  pct_disc COVID i.month_inicio i.year_inicio, absorb(i.inst_factor) cluster(inst_factor)
 est store A
 qui reghdfe  pct_disc COVID i.month_inicio i.year_inicio if inst_salud==1, absorb(i.inst_factor) cluster(inst_factor)
 est store B
 qui reghdfe  pct_disc COVID i.month_inicio i.year_inicio if inst_salud==0, absorb(i.inst_factor) cluster(inst_factor)
 est store C
 
  esttab A B C  ///
  using  "${dirraiz}/Output/Tabla2b_robust_nodrop.tex", replace ///
  b(3) se(3) se label star(* 0.1 ** 0.05 *** 0.01) ///
  title(OLS Estimates:   \label{lpmpsycho}) ///
  nomtitles r2(2) obslast 
 
 sum pct_cont_disc pct_disc if COVID==0
 sum               pct_disc if COVID==0 &  inst_salud==1
 sum               pct_disc if COVID==0 &  inst_salud==0 
 
 
 
 
 ***********************
 * Table 3  Robustness
 ***********************
 
 
 
 * Panel A: Multiple Hypothesis
 
  clear all
  use "${dirraiz}/Data/BASE_PANEL.dta" 
  qui reghdfe  pct_cont_disc COVID i.month_inicio i.year_inicio, absorb(i.inst_factor) cluster(inst_factor)
  regsave, pval
  keep var pval
  keep if pval!=.
  save "${dirraiz}/Output/pval1.dta", replace 
 
  clear all
  use "${dirraiz}/Data/BASE_PANEL.dta" 
  qui reghdfe  pct_cont_disc COVID i.month_inicio i.year_inicio if inst_salud==1, absorb(i.inst_factor) cluster(inst_factor)
  regsave, pval
  keep var pval
  keep if pval!=.
  save "${dirraiz}/Output/pval2.dta", replace 

  clear all
  use "${dirraiz}/Data/BASE_PANEL.dta" 
  qui reghdfe  pct_cont_disc COVID i.month_inicio i.year_inicio  if inst_salud==0, absorb(i.inst_factor) cluster(inst_factor)
  regsave, pval
  keep var pval
  keep if pval!=.
  save "${dirraiz}/Output/pval3.dta", replace 

  clear all
  use "${dirraiz}/Data/BASE_PANEL.dta" 
  qui reghdfe  pct_disc COVID i.month_inicio i.year_inicio, absorb(i.inst_factor) cluster(inst_factor)
  regsave, pval
  keep var pval
  keep if pval!=.
  save "${dirraiz}/Output/pval4.dta", replace 
 
  
  clear all
  use "${dirraiz}/Data/BASE_PANEL.dta" 
  qui reghdfe  pct_disc COVID i.month_inicio i.year_inicio if inst_salud==1, absorb(i.inst_factor) cluster(inst_factor)
  regsave, pval
  keep var pval
  keep if pval!=.
  save "${dirraiz}/Output/pval5.dta", replace 
  
  clear all
  use "${dirraiz}/Data/BASE_PANEL.dta" 
  qui reghdfe  pct_disc COVID i.month_inicio i.year_inicio if inst_salud==0, absorb(i.inst_factor) cluster(inst_factor)
  regsave, pval
  keep var pval
  keep if pval!=.
  save "${dirraiz}/Output/pval6.dta", replace 
 
  
  
  use "${dirraiz}/Output/pval1.dta"
  append using "${dirraiz}/Output/pval2.dta"
  append using "${dirraiz}/Output/pval3.dta"
  append using "${dirraiz}/Output/pval4.dta"
  append using "${dirraiz}/Output/pval5.dta"
  append using "${dirraiz}/Output/pval6.dta"

  save "${dirraiz}/Output/pval.dta", replace 
 
  cd "${dirraiz}/Output"
  
  * Open: 5. fdr_sharpended_qvalues.do and run since line 37
  * The column bky06_qval provides the q values. 
  
  save "${dirraiz}/Output/pval.dta", replace
  
  
  
  
  * Panel A: Multiple Hypothesis V9
 
  
  clear all
  use "${dirraiz}/Data/BASE_PANEL.dta" 
  qui reghdfe  pct_disc COVID i.month_inicio i.year_inicio, absorb(i.inst_factor) cluster(inst_factor)
  regsave, pval
  keep var pval
  keep if pval!=.
  save "${dirraiz}/Output/pval4.dta", replace 
 
  
  clear all
  use "${dirraiz}/Data/BASE_PANEL.dta" 
  qui reghdfe  pct_disc COVID i.month_inicio i.year_inicio if inst_salud==1, absorb(i.inst_factor) cluster(inst_factor)
  regsave, pval
  keep var pval
  keep if pval!=.
  save "${dirraiz}/Output/pval5.dta", replace 
  
  clear all
  use "${dirraiz}/Data/BASE_PANEL.dta" 
  qui reghdfe  pct_disc COVID i.month_inicio i.year_inicio if inst_salud==0, absorb(i.inst_factor) cluster(inst_factor)
  regsave, pval
  keep var pval
  keep if pval!=.
  save "${dirraiz}/Output/pval6.dta", replace 
 
  
  
  use "${dirraiz}/Output/pval4.dta"
  append using "${dirraiz}/Output/pval5.dta"
  append using "${dirraiz}/Output/pval6.dta"

  save "${dirraiz}/Output/pval.dta", replace 
 
  cd "${dirraiz}/Output"
  
  * Open: 5. fdr_sharpended_qvalues.do and run since line 37
  * The column bky06_qval provides the q values. 
  
  save "${dirraiz}/Output/pval.dta", replace
  
 
 
 
 * Panel B: Oster
  clear all
  use "${dirraiz}/Data/BASE_PANEL.dta" 
 
 reg  pct_cont_disc COVID i.month_inicio i.year_inicio i.inst_factor,  cluster(inst_factor)
 psacalc beta COVID, delta(1) rmax(.54288) /* Rmax=1.3*R2  W0*/
 psacalc beta COVID, delta(-1) rmax(.54288) /* Rmax=1.3*R2 */
 
 reg  pct_cont_disc COVID i.month_inicio i.year_inicio i.inst_factor if inst_salud==1,  cluster(inst_factor)
 psacalc beta COVID, delta(1) rmax(.54288) /* Rmax=1.3*R2  W0*/
 psacalc beta COVID, delta(-1) rmax(.54288) /* Rmax=1.3*R2 */
 
 reg  pct_cont_disc COVID i.month_inicio i.year_inicio i.inst_factor if inst_salud==0,  cluster(inst_factor)
 psacalc beta COVID, delta(1) rmax(.54288) /* Rmax=1.3*R2  W0*/
 psacalc beta COVID, delta(-1) rmax(.54288) /* Rmax=1.3*R2 */
 
 reg  pct_disc COVID i.month_inicio i.year_inicio i.inst_factor,  cluster(inst_factor)
 psacalc beta COVID, delta(1) rmax(.41301) /* Rmax=1.3*R2  W0*/
 psacalc beta COVID, delta(-1) rmax(.41301) /* Rmax=1.3*R2 */
 
 reg  pct_disc COVID i.month_inicio i.year_inicio i.inst_factor if inst_salud==1,  cluster(inst_factor)
 psacalc beta COVID, delta(1) rmax(.25129) /* Rmax=1.3*R2  W0*/
 psacalc beta COVID, delta(-1) rmax(.25129) /* Rmax=1.3*R2 */
 
 reg  pct_disc COVID i.month_inicio i.year_inicio i.inst_factor if inst_salud==0,  cluster(inst_factor)
 psacalc beta COVID, delta(1) rmax(.45669) /* Rmax=1.3*R2  W0*/
 psacalc beta COVID, delta(-1) rmax(.45669) /* Rmax=1.3*R2 */
 
 
 
 *Panel C: Oultiers 1%
 
  clear all
  use "${dirraiz}/Data/BASE_PANEL.dta" 
  
  * sum pct_cont_disc, de
  * sum pct_disc, de
  
  * histogram pct_cont_disc
  * histogram pct_disc
  
  sum ave_value_cont, de
  * 99%     80.45411 
  
  gen p99=0
  replace p99=1 if ave_value_cont<80.45411 
  tab p99
  
  
 qui reghdfe  pct_cont_disc COVID i.month_inicio i.year_inicio if p99==1, absorb(i.inst_factor) cluster(inst_factor)
 est store A
 qui reghdfe  pct_cont_disc COVID i.month_inicio i.year_inicio if p99==1 & inst_salud==1, absorb(i.inst_factor) cluster(inst_factor)
 est store B
 qui reghdfe  pct_cont_disc COVID i.month_inicio i.year_inicio if p99==1 & inst_salud==0, absorb(i.inst_factor) cluster(inst_factor)
 est store C
 qui reghdfe  pct_disc COVID i.month_inicio i.year_inicio if p99==1, absorb(i.inst_factor) cluster(inst_factor)
 est store D
 qui reghdfe  pct_disc COVID i.month_inicio i.year_inicio if p99==1 & inst_salud==1, absorb(i.inst_factor) cluster(inst_factor)
 est store E
 qui reghdfe  pct_disc COVID i.month_inicio i.year_inicio if p99==1 &  inst_salud==0, absorb(i.inst_factor) cluster(inst_factor)
 est store F
 
  esttab A B C D E F  ///
  using  "Tabla3C.tex", replace  ///
  b(3) se(3) se label star(* 0.1 ** 0.05 *** 0.01) ///
  title(OLS Estimates:   \label{lpmpsycho}) ///
  nomtitles r2(2) obslast 
 
  *Panel D: Oultiers 5%
  
   sum ave_value_cont, de
  
  * 95%     11.52729
  
  gen p95=0
  replace p95=1 if ave_value_cont<11.52729
  tab p95
  
  
 qui reghdfe  pct_cont_disc COVID i.month_inicio i.year_inicio if p95==1, absorb(i.inst_factor) cluster(inst_factor)
 est store A
 qui reghdfe  pct_cont_disc COVID i.month_inicio i.year_inicio if p95==1 & inst_salud==1, absorb(i.inst_factor) cluster(inst_factor)
 est store B
 qui reghdfe  pct_cont_disc COVID i.month_inicio i.year_inicio if p95==1 & inst_salud==0, absorb(i.inst_factor) cluster(inst_factor)
 est store C
 qui reghdfe  pct_disc COVID i.month_inicio i.year_inicio if p95==1, absorb(i.inst_factor) cluster(inst_factor)
 est store D
 qui reghdfe  pct_disc COVID i.month_inicio i.year_inicio if p95==1 & inst_salud==1, absorb(i.inst_factor) cluster(inst_factor)
 est store E
 qui reghdfe  pct_disc COVID i.month_inicio i.year_inicio if p95==1 &  inst_salud==0, absorb(i.inst_factor) cluster(inst_factor)
 est store F
 
  esttab A B C D E F  ///
  using  "Tabla3D.tex", replace ///
  b(3) se(3) se label star(* 0.1 ** 0.05 *** 0.01) ///
  title(OLS Estimates:   \label{lpmpsycho}) ///
  nomtitles r2(2) obslast 
 
  
  
 save "${dirraiz}/Data/BASE_PANEL.dta", replace

 
 **************
 * Figure I
 *************
 
 cd "${dirraiz}/Output"
 
 grstyle init
 grstyle set lpattern dot  solid     /*patron de las dos lineas */
 grstyle set linewidth    medthick  thick /*Grosor de las dos lineas */
 grstyle set plain  , horizontal compact  minor dotted
 grstyle set color  "56 108 176"       "56 108 176"  
 grstyle set symbol 
 
 
 * Contratos (%)
 
 local dep pct_cont_disc
 
 foreach v of local dep {
 *local label : variable label pmontodisc_instsalY 	
 eventdd  `v' i.month_inicio i.year_inicio,  hdfe absorb(i.inst_factor) timevar(even) cluster(inst_factor) ci(rline) ///
				graph_op(  xlabel(-9(1)9) ylabel( -.4(.2).4, angle(90)) xline(2, lcolor(red) lpattern(solid)) /*change month  
				*/ xtitle("Months since the lockdown", size(huge)) ytitle( " " ) /*
				*/ name(pct_importe_adjd_inv3p_2 , replace) title("DCTC", pos(12) size(huge))  ///
					xline(.5, lwidth(19.5) lc(gs15) lpattern(solid))  /// 
 					text(-.15 4.2 "Stay-at-home" "order ends" , j(left) size(medium) )   ///
 					text(-.15 2.4 "{&larr}", j(right) size(large) angle(horizontal))  )   
					graph save pct_cont_disc, replace 
					
}

 local dep pct_cont_disc
 
 foreach v of local dep {
 *local label : variable label pmontodisc_instsalY 	
 eventdd  `v' i.month_inicio i.year_inicio  if inst_salud==1,  hdfe absorb(i.inst_factor) timevar(even) cluster(inst_factor) ci(rline) ///
				graph_op(  xlabel(-9(1)9) ylabel( -.4(.2).4, angle(90)) xline(2, lcolor(red) lpattern(solid)) /*change month  
				*/ xtitle("Months since the lockdown", size(huge)) ytitle( " " ) /*
				*/ name(pct_importe_adjd_inv3p_2 , replace) title("DCTC (Health)", pos(12) size(huge))  ///
					xline(.5, lwidth(19.5) lc(gs15) lpattern(solid))  /// 
 					text(-.15 4.2 "Stay-at-home" "order ends" , j(left) size(medium) )   ///
 					text(-.15 2.4 "{&larr}", j(right) size(large) angle(horizontal))  )   
					graph save pct_cont_disc_instsalY, replace 
					
}

 local dep pct_cont_disc
 
 foreach v of local dep {
 *local label : variable label pmontodisc_instsalY 	
 eventdd  `v' i.month_inicio i.year_inicio  if inst_salud==0,  hdfe absorb(i.inst_factor) timevar(even) cluster(inst_factor) ci(rline) ///
				graph_op(  xlabel(-9(1)9) ylabel( -.4(.2).4, angle(90)) xline(2, lcolor(red) lpattern(solid)) /*change month  
				*/ xtitle("Months since the lockdown", size(huge)) ytitle( " " ) /*
				*/ name(pct_importe_adjd_inv3p_2 , replace) title("DCTC (Non-Health)", pos(12) size(huge))  ///
					xline(.5, lwidth(19.5) lc(gs15) lpattern(solid))  /// 
 					text(-.15 4.2 "Stay-at-home" "order ends" , j(left) size(medium) )   ///
 					text(-.15 2.4 "{&larr}", j(right) size(large) angle(horizontal))  )   
					graph save pct_cont_disc_instsalN, replace 
					
}

 
 * Valor (%)
 
 local dep  pct_disc
 
 foreach v of local dep {
 *local label : variable label `v'  
 eventdd  `v' i.month_inicio i.year_inicio  ,  hdfe absorb(i.inst_factor) timevar(even) cluster(inst_factor) ci(rline) ///
				graph_op(  xlabel(-9(1)9) ylabel( -.4(.2).4, angle(90)) xline(2, lcolor(red) lpattern(solid)) /*change month 
				*/ xtitle("Months since the lockdown",size(large)) ytitle( " " ) /*
				*/ name(pct_importe_adjd_inv3p_2 , replace) title("DCVB", pos(12) size(large))  ///
					xline(.5, lwidth(19.5) lc(gs15) lpattern(solid))  /// 
 					text(-.15 4.2 "Stay-at-home" "order ends" , j(left) size(medium) )   ///
 					text(-.15 2.4 "{&larr}", j(right) size(large) angle(horizontal))  )    
					graph save pct_disc, replace 
 }
 
 
 local dep pct_disc
 
 foreach v of local dep {
 *local label : variable label pmontodisc_instsalY 	
 eventdd  `v' i.month_inicio i.year_inicio if inst_salud==1,  hdfe absorb(i.inst_factor) timevar(even) cluster(inst_factor) ci(rline) ///
				graph_op(  xlabel(-9(1)9) ylabel( -.4(.2).4, angle(90)) xline(2, lcolor(red) lpattern(solid)) /*change month 
				*/ xtitle("Months since the lockdown",size(large)) ytitle( " " ) /*
				*/ name(pct_importe_adjd_inv3p_2 , replace) title("DCVB (Health)", pos(12) size(large))  ///
					xline(.5, lwidth(19.5) lc(gs15) lpattern(solid))  /// 
 					text(-.25 4.2 "Stay-at-home" "order ends" , j(left) size(medium) )   ///
 					text(-.25 2.4 "{&larr}", j(right) size(large) angle(horizontal))  )   
					graph save pmontodisc_instsalY, replace 
					
}


 local dep pct_disc
 
 foreach v of local dep {
 *local label : variable label pmontodisc_instsalY 	
 eventdd  `v' i.month_inicio i.year_inicio if inst_salud==0,  hdfe absorb(i.inst_factor) timevar(even) cluster(inst_factor) ci(rline) ///
				graph_op(  xlabel(-9(1)9) ylabel( -.4(.2).4, angle(90)) xline(2, lcolor(red) lpattern(solid)) /*change month 
				*/ xtitle("Months since the lockdown",size(large)) ytitle( " " ) /*
				*/ name(pct_importe_adjd_inv3p_2 , replace) title("DCVB (Non-Health)", pos(12) size(large))  ///
					xline(.5, lwidth(19.5) lc(gs15) lpattern(solid))  /// 
 					text(-.15 4.2 "Stay-at-home" "order ends" , j(left) size(medium) )   ///
 					text(-.15 2.4 "{&larr}", j(right) size(large) angle(horizontal))  )     
					graph save pmontodisc_instsalN, replace 
					
}

 

 grc1leg pct_cont_disc.gph   pct_disc.gph  pct_cont_disc_instsalY.gph  pmontodisc_instsalY.gph pct_cont_disc_instsalN.gph     pmontodisc_instsalN.gph  ///
 , iscale(.36) col(2)    imargin(0 0 0 0 ) name(g7, replace)  
 graph display g7, xsize(8) ysize(10)
graph export "${dirraiz}/Output/Main.png", as(png) width(1000) replace

*cd "/Users/adansilverio/Dropbox/Paper 32 IMCO Adan/Output"
*cd "C:\Users\prude\Dropbox\Paper 32 IMCO Adan"


grc1leg    pct_disc.gph   pmontodisc_instsalY.gph    pmontodisc_instsalN.gph  ///
 , iscale(.71) col(1)    imargin(0 0 0 0 ) name(g7, replace)  
 graph display g7, xsize(8) ysize(10)
*graph export "/Users/adansilverio/Dropbox/Paper 32 IMCO Adan/Output/MainV9.png", as(png) width(1000) replace
graph export "${dirraiz}\Output\MainV9.png", as(png) width(1000) replace

*grc1leg pct_cont_disc.gph   pct_disc.gph   pmontodisc_instsalY.gph    pmontodisc_instsalN.gph  ///
*, iscale(.7) col(1)    imargin(1 1 1 1 ) name(g7, replace)  
*graph display g7, xsize(5) ysize(9)
*graph export "${dirraiz}/Output/Main.png", as(png) width(1000) replace


 *************************************
 * Figure Robustness without SEDENA
 * inst_factor = 245 identifies SEDENA
 *************************************
 
local dep pct_cont_disc
 
 foreach v of local dep {
 *local label : variable label pmontodisc_instsalY 	
 eventdd  `v' i.month_inicio i.year_inicio  if inst_salud==0 & inst_factor != 245,  hdfe absorb(i.inst_factor) timevar(even) cluster(inst_factor) ci(rline) ///
				graph_op(  xlabel(-9(1)9) ylabel( -.4(.2).4, angle(90)) xline(2, lcolor(red) lpattern(solid)) /*change month  
				*/ xtitle("Months since the lockdown", size(large)) ytitle( " " ) /*
				*/ name(pct_importe_adjd_inv3p_2 , replace) title("DCTC (Non-Health)", pos(12) size(large))  ///
					xline(.5, lwidth(19.5) lc(gs15) lpattern(solid))  /// 
 					text(-.15 4.2 "Stay-at-home" "order ends" , j(left) size(medium) )   ///
 					text(-.15 2.4 "{&larr}", j(right) size(large) angle(horizontal))  )   
					graph save pct_cont_disc_instsalN_nosedena, replace 
					
}


 local dep pct_disc
 
 foreach v of local dep {
 *local label : variable label pmontodisc_instsalY 	
 eventdd  `v' i.month_inicio i.year_inicio if inst_salud==0 & inst_factor != 245,  hdfe absorb(i.inst_factor) timevar(even) cluster(inst_factor) ci(rline) ///
				graph_op(  xlabel(-9(1)9) ylabel( -.4(.2).4, angle(90)) xline(2, lcolor(red) lpattern(solid)) /*change month 
				*/ xtitle("Months since the lockdown",size(large)) ytitle( " " ) /*
				*/ name(pct_importe_adjd_inv3p_2 , replace) title("DCVB (Non-Health)", pos(12) size(large))  ///
					xline(.5, lwidth(19.5) lc(gs15) lpattern(solid))  /// 
 					text(-.15 4.2 "Stay-at-home" "order ends" , j(left) size(medium) )   ///
 					text(-.15 2.4 "{&larr}", j(right) size(large) angle(horizontal))  )     
					graph save pmontodisc_instsalN_nosedena, replace 
					
}

grc1leg pct_cont_disc_instsalN_nosedena.gph   pmontodisc_instsalN_nosedena.gph    ///
, iscale(.7) col(1)    imargin(1 1 1 1 ) name(g7, replace)  
graph display g7, xsize(5) ysize(9)
graph export "${dirraiz}/Output/Robust_event_nosedena.png", as(png) width(1000) replace
 

 
 **************
 * Figure II
 *************
 


local dep hhi_numc

 foreach v of local dep {
 *local label : variable label pmontodisc_instsalY 	
 eventdd  `v' i.month_inicio i.year_inicio ,  hdfe absorb(i.inst_factor) timevar(even) cluster(inst_factor) ci(rline) ///
				graph_op(  xlabel(-9(1)9) ylabel( -4000(1000)3000, angle(90)) xline(2, lcolor(red) lpattern(solid)) /*change month  
				*/ xtitle("Months since the lockdown",size(huge)) ytitle( "HHI",size(huge) ) /*
				*/ name(pct_importe_adjd_inv3p_2 , replace) title("HHI - Number of contracts", pos(12) size(huge))  ///
					xline(.5, lwidth(19.5) lc(gs15) lpattern(solid))  /// 
 					text(-1000 4.2 "Stay-at-home" "order ends" , j(left) size(medium) )   ///
 					text(-1000 2.4 "{&larr}", j(right) size(large) angle(horizontal))  )   
					graph save hhi_numc, replace 
					
}
 
 local dep hhi_numc
 
 foreach v of local dep {
 *local label : variable label pmontodisc_instsalY 	
 eventdd  `v' i.month_inicio i.year_inicio if inst_salud == 1,  hdfe absorb(i.inst_factor) timevar(even) cluster(inst_factor) ci(rline) ///
				graph_op(  xlabel(-9(1)9) ylabel( -4000(1000)3000, angle(90)) xline(2, lcolor(red) lpattern(solid)) /*change month  
				*/ xtitle("Months since the lockdown",size(huge)) ytitle( "HHI",size(huge) ) /*
				*/ name(pct_importe_adjd_inv3p_2 , replace) title("HHI - Number of contracts (Health)", pos(12) size(huge))  ///
					xline(.5, lwidth(19.5) lc(gs15) lpattern(solid))  /// 
 					text(-1000 4.2 "Stay-at-home" "order ends" , j(left) size(medium) )   ///
 					text(-1000 2.4 "{&larr}", j(right) size(large) angle(horizontal))  )   
					graph save hhi_numc_instsalY, replace 
					
}

local dep hhi_numc


 foreach v of local dep {
 *local label : variable label pmontodisc_instsalY 	
 eventdd  `v' i.month_inicio i.year_inicio if inst_salud == 0,  hdfe absorb(i.inst_factor) timevar(even) cluster(inst_factor) ci(rline) ///
				graph_op(  xlabel(-9(1)9) ylabel( -4000(1000)3000, angle(90)) xline(2, lcolor(red) lpattern(solid)) /*change month  
				*/ xtitle("Months since the lockdown",size(huge)) ytitle( "HHI",size(huge) ) /*
				*/ name(pct_importe_adjd_inv3p_2 , replace) title("HHI - Number of contracts (Non-Health)", pos(12) size(vlarge))  ///
					xline(.5, lwidth(19.5) lc(gs15) lpattern(solid))  /// 
 					text(-1000 4.2 "Stay-at-home" "order ends" , j(left) size(medium) )   ///
 					text(-1000 2.4 "{&larr}", j(right) size(large) angle(horizontal))  )   
					graph save hhi_numc_instsalN, replace 
					
}



 local dep hhi_monto
 
  foreach v of local dep {
 *local label : variable label pmontodisc_instsalY 	
 eventdd  `v' i.month_inicio i.year_inicio ,  hdfe absorb(i.inst_factor) timevar(even) cluster(inst_factor) ci(rline) ///
				graph_op(  xlabel(-9(1)9) ylabel( -4000(1000)3000, angle(90)) xline(2, lcolor(red) lpattern(solid)) /*change month  
				*/ xtitle("Months since the lockdown",size(huge)) ytitle( "HHI",size(huge) ) /*
				*/ name(pct_importe_adjd_inv3p_2 , replace) title("HHI - Contract value", pos(12) size(huge))  ///
					xline(.5, lwidth(19.5) lc(gs15) lpattern(solid))  /// 
 					text(-1000 4.2 "Stay-at-home" "order ends" , j(left) size(medium) )   ///
 					text(-1000 2.4 "{&larr}", j(right) size(large) angle(horizontal))  )   
					graph save hhi_monto, replace 
					
}
 
  local dep hhi_monto
 
 foreach v of local dep {
 *local label : variable label pmontodisc_instsalY 	
 eventdd  `v' i.month_inicio i.year_inicio if inst_salud == 1,  hdfe absorb(i.inst_factor) timevar(even) cluster(inst_factor) ci(rline) ///
				graph_op(  xlabel(-9(1)9) ylabel( -4000(1000)3000, angle(90)) xline(2, lcolor(red) lpattern(solid)) /*change month  
				*/ xtitle("Months since the lockdown",size(huge)) ytitle( "HHI",size(huge) ) /*
				*/ name(pct_importe_adjd_inv3p_2 , replace) title("HHI - Contract value (Health)", pos(12) size(huge))  ///
					xline(.5, lwidth(19.5) lc(gs15) lpattern(solid))  /// 
 					text(-1000 4.2 "Stay-at-home" "order ends" , j(left) size(medium) )   ///
 					text(-1000 2.4 "{&larr}", j(right) size(large) angle(horizontal))  )   
					graph save hhi_monto_instsalY, replace 
					
}

 local dep hhi_monto

 foreach v of local dep {
 *local label : variable label pmontodisc_instsalY 	
 eventdd  `v' i.month_inicio i.year_inicio if inst_salud == 0,  hdfe absorb(i.inst_factor) timevar(even) cluster(inst_factor) ci(rline) ///
				graph_op(  xlabel(-9(1)9) ylabel( -4000(1000)3000, angle(90)) xline(2, lcolor(red) lpattern(solid)) /*change month  
				*/ xtitle("Months since the lockdown",size(huge)) ytitle( "HHI",size(huge) ) /*
				*/ name(pct_importe_adjd_inv3p_2 , replace) title("HHI - Contract value (Non-Health)", pos(12) size(huge))  ///
					xline(.5, lwidth(19.5) lc(gs15) lpattern(solid))  /// 
 					text(-1000 4.2 "Stay-at-home" "order ends" , j(left) size(medium) )   ///
 					text(-1000 2.4 "{&larr}", j(right) size(large) angle(horizontal))  )   
					graph save hhi_monto_instsalN, replace 
					
}

 grc1leg hhi_numc.gph   hhi_monto.gph  hhi_numc_instsalY.gph  hhi_monto_instsalY.gph  hhi_numc_instsalN.gph  hhi_monto_instsalN.gph  ///
 , iscale(.36) col(2)    imargin(0 0 0 0 ) name(g7, replace)  
 graph display g7, xsize(8) ysize(10)
graph export "${dirraiz}/Output/Main2.png", as(png) width(1000) replace



*grc1leg hhi_monto_instsalY.gph  hhi_monto_instsalN.gph  hhi_numc_instsalY.gph hhi_numc_instsalN.gph ///
*, iscale(.7) col(1)    imargin(1 1 1 1 ) name(g7, replace)  
*graph display g7, xsize(5) ysize(9)
*graph export "${dirraiz}/Output/Main2.png", as(png) width(1000) replace 


**********************
* Figure Robustness 
********************** 

use "${dirraiz}/Data/BASE_PANEL.dta", replace


* Rambachan and Roth (2023)

* ------------ 
*    DiD         -- not yet completed
* ------------

reghdfe  pct_disc COVID , absorb(i.inst_factor i.month_inicio i.year_inicio) cluster(inst_factor) 

reghdfe  pct_disc COVID  if inst_salud==1, absorb(i.inst_factor i.month_inicio i.year_inicio) cluster(inst_factor)

reghdfe  pct_disc COVID  if inst_salud==0, absorb(i.inst_factor i.month_inicio i.year_inicio) cluster(inst_factor) 

* ------------ 
* Event study 
* ------------

gen even_positivo = even + 10 /*All event times are now positive. We don't want negative numbers to use variable as factor in regression*/
tab even_positivo

*Overall
reghdfe pct_disc b9.even_positivo , absorb(i.inst_factor i.month_inicio i.year_inicio) cluster(inst_factor) noconstant
local plotopts ytitle("Estimate and 95% Conf. Int.") title("Effect on dins")
coefplot, vertical yline(0) ciopts(recast(rcap)) xlabel(,angle(45)) `plotopts'
honestdid, pre(1/8) post(10/19) mvec(0.5(0.5)2) 

matrix l_vec = 0.1 \ 0.1 \ 0.1 \ 0.1 \ 0.1 \ 0.1 \ 0.1 \ 0.1 \ 0.1 \ 0.1 
local plotopts xtitle(Mbar) ytitle(95% Robust CI)
honestdid, l_vec(l_vec) pre(1/8) post(10/19) mvec(0(0.5)2) coefplot `plotopts' 

*Non-health
reghdfe pct_disc b9.even_positivo if inst_salud == 0, absorb(i.inst_factor i.month_inicio i.year_inicio) cluster(inst_factor) noconstant
local plotopts ytitle("Estimate and 95% Conf. Int.") title("Effect on dins")
coefplot, vertical yline(0) ciopts(recast(rcap)) xlabel(,angle(45)) `plotopts'
honestdid, pre(1/8) post(10/19) mvec(0.5(0.5)2) 

matrix l_vec = 0.1 \ 0.1 \ 0.1 \ 0.1 \ 0.1 \ 0.1 \ 0 \ 0 \ 0 \ 0 
local plotopts xtitle(Mbar) ytitle(95% Robust CI)
honestdid, l_vec(l_vec) pre(1/8) post(10/19) mvec(0(0.5)2) coefplot `plotopts' 

*Health
reghdfe pct_disc b9.even_positivo if inst_salud == 1, absorb(i.inst_factor i.month_inicio i.year_inicio) cluster(inst_factor) noconstant
local plotopts ytitle("Estimate and 95% Conf. Int.") title("Effect on dins")
coefplot, vertical yline(0) ciopts(recast(rcap)) xlabel(,angle(45)) `plotopts'
honestdid, pre(1/8) post(10/19) mvec(0.5(0.5)2) 

matrix l_vec = 0.1 \ 0.1 \ 0.1 \ 0.1 \ 0.1 \ 0.1 \ 0.1 \ 0.1 \ 0.1 \ 0.1 
local plotopts xtitle(Mbar) ytitle(95% Robust CI)
honestdid, l_vec(l_vec) pre(1/8) post(10/19) mvec(0(0.5)2) coefplot `plotopts' 





* Taking one institution out at time


egen inst_factor2 = group(inst_factor)
tab inst_factor2 
egen inst_factor2_salud = group(inst_factor) if inst_salud == 1  
tab inst_factor2_salud 
egen inst_factor2_nosalud = group(inst_factor) if inst_salud == 0 
tab inst_factor2_nosalud 
  
 forval y = 1(1)64 { 
 reghdfe  pct_cont_disc COVID i.month_inicio  i.year_inicio if inst_factor2 != `y' , absorb(i.inst_factor) cluster(inst_factor)
 eststo reg1_`y'
 }
 esttab reg1_* using robust_col1.csv, replace nostar se(3) noparentheses

 forval x = 1(1)64 { 
 qui reghdfe  pct_disc COVID  i.month_inicio i.year_inicio if inst_factor2  != `x'  , absorb(i.inst_factor ) cluster(inst_factor) 
 eststo reg2_`x'
 }
 esttab reg2_* using robust_col2.csv, replace nostar se(3) noparentheses
 
 forval xsalud = 1(1)13 { 
 qui reghdfe  pct_disc COVID i.month_inicio i.year_inicio  if inst_factor2_salud != `xsalud' & inst_salud==1 , absorb(i.inst_factor) cluster(inst_factor)
 eststo reg3_`xsalud'
 }
 esttab reg3_* using robust_col3.csv, replace nostar se(3) noparentheses

 
 forval xnosalud = 1(1)51 { 
 qui reghdfe  pct_disc COVID i.month_inicio i.year_inicio  if inst_factor2_nosalud != `xnosalud' & inst_salud==0 , absorb(i.inst_factor) cluster(inst_factor)
 eststo reg4_`xnosalud'
 }
 esttab reg4_* using robust_col4.csv, replace nostar se(3) noparentheses


 
 forval xsalud = 1(1)13 { 
 qui reghdfe  pct_cont_disc COVID i.month_inicio i.year_inicio  if inst_factor2_salud != `xsalud' & inst_salud==1 , absorb(i.inst_factor) cluster(inst_factor)
 eststo reg5_`xsalud'
 }
 esttab reg5_* using robust_col5.csv, replace nostar se(3) noparentheses

 
 forval xnosalud = 1(1)51 { 
 qui reghdfe  pct_cont_disc COVID i.month_inicio i.year_inicio  if inst_factor2_nosalud != `xnosalud' & inst_salud==0 , absorb(i.inst_factor) cluster(inst_factor)
 eststo reg6_`xnosalud'
 }
 esttab reg6_* using robust_col6.csv, replace nostar se(3) noparentheses
 
 
 
 